﻿using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Windows.Forms;


namespace lp1415_11951_TP2.model
{
    /// <summary>
    /// Classe para calculos de Estatísticas
    /// </summary>
    internal class Estatisticas
    {
        private static SQLiteConnection m_dbConnection;
        private SQLiteCommand cmd;
        private SQLiteConnection cn;
        private List<double> listaValor;
        private List<double> desvio;
        private List<string> teste;
        private List<Dictionary<String, double>> listaTotal;
        private Dictionary<String, double> lista;
        private List<String> items;
        private double resultado;
        private double mediaVal;
        private double somaQuadradoDesvio;
        private double variancia;
        private double desvioPadrao;
        private double total;
        private string titulo;
        private SQLiteDataReader dr;
        private CultureInfo enUk = CultureInfo.CreateSpecificCulture("en-Uk");

        /// <summary>
        /// Chama funções internas.
        /// </summary>
        /// <param name="titulo">Recebe o título do gráfico.</param>
        /// <param name="campo">Recebe o campo da tabela.</param>
        /// <param name="value1">Recebe a primeira data.</param>
        /// <param name="value2">Recebe a segunda data.</param>
        public void estatisticas(string titulo, string campo, short value1, short value2)
        {
            Titulo = titulo;
            abrirConexao();
            dadosPopulacao(campo, value1, value2);
            calculoEstatisticas();
        }
        
        /// <summary>
        /// Abrir uma conexão com a base de dados.
        /// </summary>
        public void abrirConexao()
        {
            cn = new SQLiteConnection();
            cmd = new SQLiteCommand();
            //Connect to SQLite database
            cn.ConnectionString = @"Data Source=IPC_Base.db;Version=3;";
            cn.Open();
        }

        /// <summary>
        /// Faz uma consulta e preenche uma lista com os dadoos de um intervalo de tempo.
        /// </summary>
        /// <param name="campo">Recebe o campo da tabela a pesquisar.</param>
        /// <param name="value1">Recebe a primeira data.</param>
        /// <param name="value2">Recebe a segunda data.</param>
        public void dadosPopulacao(string campo, short value1, short value2)
        {

            listaValor = new List<double>();
            ListaValor.Clear();

            cmd.Connection = cn;
            try
            {
                cmd.CommandText = "SELECT " + campo + " FROM IPC_Portugal  WHERE ano BETWEEN " + value1 + " AND " +
                                  value2 + " ";

                //Retrieve the records using SQLiteDataReader
                SQLiteDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    //MessageBox.Show(dr["ipc_global"].ToString());
                    listaValor.Add(Convert.ToDouble(dr[campo]));
                    //display records
                }
            }
            catch (Exception ex)
            {

                //display any exeptions
                MessageBox.Show(ex.Message);
            }
            finally
            {
                cn.Close();
            }

        }

        /// <summary>
        /// Calcula as estatísticas.
        /// </summary>
        /// <returns></returns>
        public List<String> calculoEstatisticas()
        {

            Desvio = new List<double>();
            List<double> quadradoDesvio = new List<double>();

            //Total dos valores
            Total = ListaValor.Count();

            //Média dos valores
            try
            {
                MediaVal = ListaValor.Average();
            }
            catch (Exception)
            {
                MessageBox.Show("Não foi escolhido um range de datas!");

                throw;
            }

            //Calculo dos desvio
            foreach (double val in ListaValor)
            {
                Desvio.Add(val - MediaVal);
            }

            //Calculo 
            foreach (double val in desvio)
            {
                quadradoDesvio.Add(Math.Pow(val, 2));
            }

            //Soma dos desvios ao Quadrado
            SomaQuadradoDesvio = quadradoDesvio.Sum();

            //A soma dos quadrados dos desvios dividida pelo número de ocorrências é chamada de variância.
            Variancia = SomaQuadradoDesvio/Total;

            //desvio padrão. Como os desvios foram elevados ao quadrado, deve-se tirar a raiz quadrada da variância e achar o desvio padrão
            DesvioPadrao = Math.Sqrt(Variancia);

            //MessageBox.Show("Total: " + String.Format("{0:0.00}", total)).ToString();
            //MessageBox.Show("Média: " + String.Format("{0:0.00}", mediaVal)).ToString();
            //MessageBox.Show("Soma Desvio ao Quadrado: " + String.Format("{0:0.00}", somaQuadradoDesvio)).ToString();

            //MessageBox.Show("Desvio Padrão: " + String.Format(enUk, "{0:0,0.00}", desvioPadrao)).ToString();

            //MessageBox.Show("Variância: " + String.Format(enUk,"{0:0.00}", variancia)).ToString();

            //listaValor.Clear();
            // return somaQuadradoDesvio;
            items = new List<String>();
            items.Add(Titulo);
            items.Add("População = " + Convert.ToDecimal(Total).ToString("#,0.00", new CultureInfo("pt-PT")));
            items.Add("Média = " + Convert.ToDecimal(MediaVal).ToString("#,0.00", new CultureInfo("pt-PT")));
            items.Add("Variância = " + Convert.ToDecimal(Variancia).ToString("#,0.00", new CultureInfo("pt-PT")));
            items.Add("Desvio Padrão = " + Convert.ToDecimal(DesvioPadrao).ToString("#,0.00", new CultureInfo("pt-PT")));

            return items;
        }

        /// <summary>
        /// Gera a página principal dos gráficos.
        /// </summary>
        public void home()
        {
            using (System.IO.StreamWriter sw = new System.IO.StreamWriter(@"Graficos\home.html"))
            {
                sw.WriteLine("<!DOCTYPE html>");
                sw.WriteLine("<html>");
                sw.WriteLine("<meta charset='UTF-8'>");
                sw.WriteLine("<head>");
                sw.WriteLine("<title>IPC Portugal 1977/2013</title>);");

                sw.WriteLine("<!--Load the AJAX API-->");

                sw.WriteLine("<!-- Latest compiled and minified CSS -->");
                sw.WriteLine("<link rel='stylesheet' href='css/bootstrap.min.css'>");
                sw.WriteLine("<link href='css/simple-sidebar.css' rel='stylesheet'>");
                sw.WriteLine("<!-- Optional theme -->");
                sw.WriteLine("<link rel='stylesheet' href='css/bootstrap-theme.min.css'>");
                sw.WriteLine("<!-- Latest compiled and minified JavaScript -->");
                sw.WriteLine("<script src='js/bootstrap.min.js'></script>");

                sw.WriteLine("<script type='text/javascript' src='js/jsapi.js'></script>");
                sw.WriteLine("<script type='text/javascript'>");
                // Load the Visualization API and the piechart package.
                sw.WriteLine("google.load('visualization', '1.0', {'packages':['corechart']});");

                // Set a callback to run when the Google Visualization API is loaded.
                sw.WriteLine("google.setOnLoadCallback(drawChart);");

                // Callback that creates and populates a data table,
                // instantiates the pie chart, passes in the data and
                // draws it.
                sw.WriteLine("function drawChart() {");

                // Create the data table.

                sw.WriteLine("var data3 = new google.visualization.DataTable();");
                sw.WriteLine("data3.addColumn('number', 'Ano');");
                sw.WriteLine("data3.addColumn('number', 'IPC');");
                sw.WriteLine("data3.addColumn('number', 'Variação Anual TI');");
                sw.WriteLine("data3.addColumn('number', 'Remunecação Mínima');");
                sw.WriteLine("data3.addColumn('number', 'Remunecação Máxima');");
                sw.WriteLine("data3.addColumn('number', 'PIB PC Anual');");
                sw.WriteLine("data3.addColumn('number', 'Rendimento Nacional Bruto PC Anual');");
                sw.WriteLine("data3.addColumn('number', 'Rendimento Disponível Bruto PC Anual');");
                sw.WriteLine("data3.addColumn('number', 'Remuneração PC Anual');");
                sw.WriteLine("data3.addRows([");

                abrirConexao();
                cmd.Connection = cn;
                try
                {
                    cmd.CommandText = "SELECT * FROM IPC_Portugal ";
                    int count = 0;
                    //Retrieve the records using SQLiteDataReader
                    dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        if (count <= 37)
                        {
                            sw.WriteLine("[" + Convert.ToInt16(dr["ano"]) + ", "
                                         +
                                         String.Format(enUk, "{0:##.###,##}", Convert.ToDecimal(dr["ipc_global"])/1000) +
                                         ", "
                                         +
                                         String.Format(enUk, "{0:##.###,##}",
                                             Convert.ToDecimal(dr["variacao_anual"])/1000) + ", "
                                         +
                                         String.Format(enUk, "{0:##.###,##}",
                                             Convert.ToDecimal(dr["remuneracao_min"])/1000) + ", "
                                         +
                                         String.Format(enUk, "{0:##.###,##}",
                                             Convert.ToDecimal(dr["remuneracao_max"])/1000) + ", "
                                         + String.Format(enUk, "{0:##.###,##}", Convert.ToDecimal(dr["pib"])/1000) +
                                         ", "
                                         +
                                         String.Format(enUk, "{0:##.###,##}",
                                             Convert.ToDecimal(dr["rendim_nacional"])/1000) + ", "
                                         +
                                         String.Format(enUk, "{0:##.###,##}", Convert.ToDecimal(dr["rendim_disp"])/1000) +
                                         ", "
                                         +
                                         String.Format(enUk, "{0:##.###,##}",
                                             Convert.ToDecimal(dr["remuneracoes_percapita"])/1000) + "],");
                            count += 1;
                        }
                    }
                }
                catch (Exception ex)
                {

                    //display any exeptions
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    cn.Close();
                }
                sw.WriteLine("]);");

                // Set chart options
                sw.WriteLine("var options3 = {");
                sw.WriteLine("title : 'IPC Portugal', 'width':1024, 'height':800,");
                sw.WriteLine("vAxis: {title: 'Valores'},");
                sw.WriteLine("hAxis: {title: 'Anos'}");
                sw.WriteLine("};");

                // Instantiate and draw our chart, passing in some options.
                sw.WriteLine("var chart3 = new google.visualization.LineChart(document.getElementById('chart_div3'));");
                sw.WriteLine("chart3.draw(data3, options3);");

                sw.WriteLine("}");
                sw.WriteLine("</script>");
                sw.WriteLine("</head>");
                sw.WriteLine("<body>");

                sw.WriteLine(" <div id='wrapper'>");

                sw.WriteLine("<!-- Sidebar -->");
                sw.WriteLine("<div id='sidebar-wrapper'>");

                sw.WriteLine("<ul class='sidebar-nav'>");
                sw.WriteLine("</br> </br> </br>");
                sw.WriteLine("<li class='sidebar-brand'>");
                sw.WriteLine("<a href='home.html' role='button'>Home Gráficos</a>");
                sw.WriteLine("</li>");
                sw.WriteLine("<li>");
                sw.WriteLine("<p><a href='graf1.html' role='button'>IPC</a></p>");
                sw.WriteLine("</li>");
                sw.WriteLine(" <li>");
                sw.WriteLine("<p><a href='graf6.html' role='button'>Rendimento Nacional PC Anual</a></p>");
                sw.WriteLine("</li>");
                sw.WriteLine(" <li>");
                sw.WriteLine("<p><a href='graf3.html' role='button'>Remuneração Mínima</a></p>");
                sw.WriteLine("</li>");
                sw.WriteLine("<li>");
                sw.WriteLine("<p><a href='graf4.html' role='button'>Remuneração Máxima</a></p>");
                sw.WriteLine(" </li>");
                sw.WriteLine("<li>");
                sw.WriteLine("<p><a href='graf5.html' role='button'>PIB Per Capta anual</a></p>");
                sw.WriteLine("</li>");
                sw.WriteLine("<li>");
                sw.WriteLine("<p><a href='graf2.html' role='button'>Variação Anual Taxa de Inflação</a></p>");
                sw.WriteLine("</li>");
                sw.WriteLine("<li>");
                sw.WriteLine("<p><a href='graf7.html' role='button'>Rendimento Disponível PC Anual</a></p>");
                sw.WriteLine("</li>");
                sw.WriteLine("<li>");
                sw.WriteLine("<p><a href='graf8.html' role='button'>Remuneração Per Capta Anual</a></p>");
                sw.WriteLine("</li>");
                sw.WriteLine("</ul>");
                sw.WriteLine("</div>");
                sw.WriteLine("<!-- /#sidebar-wrapper -->");

                sw.WriteLine("<!-- Page Content -->");
                sw.WriteLine("<div id='page-content-wrapper'>");
                sw.WriteLine("<div class='container-fluid'>");
                sw.WriteLine("<div class='row'>");

                sw.WriteLine("</div>");
                sw.WriteLine("</div>");
                sw.WriteLine("</div>");
                sw.WriteLine("<!-- /#page-content-wrapper -->");
                sw.WriteLine("<nav class='navbar navbar-inverse navbar-fixed-top'>");
                sw.WriteLine("<div class='container'>");
                sw.WriteLine("<div class='navbar-header'>");
                sw.WriteLine(
                    "<button type='button' class='navbar-toggle collapsed' data-toggle='collapse' data-target='#navbar' aria-expanded='false' aria-controls='navbar'>");
                sw.WriteLine("<span class='sr-only'>Toggle navigation</span>");
                sw.WriteLine("<span class='icon-bar'></span>");
                sw.WriteLine("<span class='icon-bar'></span>");
                sw.WriteLine("<span class='icon-bar'></span>");
                sw.WriteLine("</button>");
                sw.WriteLine(
                    "<a class='navbar-brand' href='https://code.google.com/p/lp1415-11951/'>Trabalho de Linguagem de Programação 2014/2015</a>");
                sw.WriteLine("<div>");
                sw.WriteLine("<div id='navbar' class='navbar-collapse collapse'>");

                sw.WriteLine("<div><!--/.navbar-collapse -->");
                sw.WriteLine("<div>");
                sw.WriteLine("</nav>");

                sw.WriteLine("<!-- Main jumbotron for a primary marketing message or call to action -->");
                sw.WriteLine("<div class='jumbotron'>");
                sw.WriteLine("<div class='container'>");
                sw.WriteLine("<h1>IPC Portugal 1977/2013</h1>");

                sw.WriteLine("</div>");
                sw.WriteLine("</div>");
                sw.WriteLine("<!-- /#wrapper -->");


                sw.WriteLine("<div class='container'>");
                sw.WriteLine("<div class='col-lg-12'>");
                sw.WriteLine("<a href='home.html' class='btn btn-default' id='menu-toggle'>Home</a>");
                sw.WriteLine("</div>");
                sw.WriteLine("<!-- Example row of columns -->");

                sw.WriteLine("<div class='row'>");

                sw.WriteLine("<div class='col-md-12'>");
                sw.WriteLine("<h2></h2>");
                sw.WriteLine("<div id='chart_div3'>CAMPO3</div>");
                sw.WriteLine("</div>");
                sw.WriteLine("</div>");

                sw.WriteLine("<!--Divs that will hold the charts-->");
                sw.WriteLine("</div> <!-- /row -->");

                sw.WriteLine("<footer>");
                sw.WriteLine("<p>&copy; Adriano Leal 11951</p>");
                sw.WriteLine("</footer>");
                sw.WriteLine("</div> <!-- /container -->");
                sw.WriteLine("</body>");

                sw.WriteLine("</html>");
                sw.Close();

                //Abre o html no browser definido.
                System.Diagnostics.Process.Start(@"Graficos\home.html");
            }
        }

        /// <summary>
        /// Gerar páginas dos gráficos
        /// </summary>
        /// <param name="titulo">Recebe o título do gráfico</param>
        /// <param name="campo">Recebe o campo da tabela</param>
        /// <param name="value1">Recebe o valor da primeira data.</param>
        /// <param name="value2">Recebe o valor da segunda data.</param>
        /// <param name="count">Recebe um valor inteiro para geração do gráfico específico</param>
        /// <param name="flag">Recebe um inteiro 1 abre o html ou 0 não</param>
        public void grafico_estatisticas(string titulo, string campo, short value1, short value2, int count, int flag)
        {
            using (StreamWriter sw = new StreamWriter(@"Graficos\graf" + count + ".html"))
            {
                sw.WriteLine("<!DOCTYPE html>");
                sw.WriteLine("<html>");
                sw.WriteLine("<meta charset='UTF-8'>");
                sw.WriteLine("<head>");
                sw.WriteLine("<title>" + titulo + "</title>);");
                sw.WriteLine("<!--Load the AJAX API-->");

                sw.WriteLine("<!-- Latest compiled and minified CSS -->");
                sw.WriteLine("<link rel='stylesheet' href='css/bootstrap.min.css'>");
                sw.WriteLine("<link href='css/simple-sidebar.css' rel='stylesheet'>");
                sw.WriteLine("<!-- Optional theme -->");
                sw.WriteLine("<link rel='stylesheet' href='css/bootstrap-theme.min.css'>");
                sw.WriteLine("<!-- Latest compiled and minified JavaScript -->");
                sw.WriteLine("<script src='js/bootstrap.min.js'></script>");

                sw.WriteLine("<script type='text/javascript' src='js/jsapi.js'></script>");
                sw.WriteLine("<script type='text/javascript'>");
                // Load the Visualization API and the piechart package.
                sw.WriteLine("google.load('visualization', '1.0', {'packages':['corechart']});");

                // Set a callback to run when the Google Visualization API is loaded.
                sw.WriteLine("google.setOnLoadCallback(drawChart);");

                // Callback that creates and populates a data table,
                // instantiates the pie chart, passes in the data and
                // draws it.
                sw.WriteLine("function drawChart() {");

                // Create the data table.
                sw.WriteLine("var data = new google.visualization.DataTable();");
                sw.WriteLine("data.addColumn('string', 'Topping');");
                sw.WriteLine("data.addColumn('number', 'Slices');");
                sw.WriteLine("data.addRows([");
                sw.WriteLine("['Média',  " + String.Format(enUk, "{0:00.00}", Convert.ToDecimal(MediaVal)) + "],");
                sw.WriteLine("['Desvio Padrão', " + String.Format(enUk, "{0:00.00}", Convert.ToDecimal(DesvioPadrao)) +
                             "]");
                sw.WriteLine("]);");
                // Create the data table.
                sw.WriteLine("var data2 = new google.visualization.arrayToDataTable([");
                sw.WriteLine("['Anos', 'Média', 'Desvio Padrão'],");
                sw.WriteLine("['" + value1 + "/" + value2 + "',  " +
                             String.Format(enUk, "{0:00.00}", Convert.ToDecimal(MediaVal)) + "," +
                             String.Format(enUk, "{0:00.00}", Convert.ToDecimal(DesvioPadrao)) + "]");
                sw.WriteLine("]);");

                sw.WriteLine("var data3 = google.visualization.arrayToDataTable([");
                sw.WriteLine("['Ano', '" + titulo + "'],");

                abrirConexao();
                cmd.Connection = cn;
                try
                {
                    cmd.CommandText = "SELECT * FROM IPC_Portugal WHERE ano BETWEEN " + value1 + " AND " + value2 + ";";

                    //Retrieve the records using SQLiteDataReader
                    dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        sw.WriteLine("[" + Convert.ToString(dr["ano"]) + ", " +
                                     String.Format(enUk, "{0:##.###,##}", Convert.ToDecimal(dr[campo])) + "],");
                    }
                }
                catch (Exception ex)
                {

                    //display any exeptions
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    cn.Close();
                }
                sw.WriteLine("]);");

                // Set chart options
                sw.WriteLine("var options = {'title':'Média e Desvio Padrão', 'width':400, 'height':300};");

                // Set chart options
                sw.WriteLine("var options2 = {");
                sw.WriteLine("title : 'Média e Desvio Padrão', 'width':640, 'height':480,");
                sw.WriteLine("vAxis: {title: 'Valores'},");
                sw.WriteLine("hAxis: {title: 'Anos'},");
                sw.WriteLine("seriesType: 'bars',");
                sw.WriteLine("series: {5: {type: 'line'}}");
                sw.WriteLine("};");

                // Set chart options
                sw.WriteLine("var options3 = {");
                sw.WriteLine("title : '" + titulo + "', 'width':640, 'height':480,");
                sw.WriteLine("vAxis: {title: 'Valores'},");
                sw.WriteLine("hAxis: {title: 'Anos'}");
                sw.WriteLine("};");

                // Set chart options
                sw.WriteLine("var options4 = {");
                sw.WriteLine("title : '" + titulo + "', 'width':640, 'height':480,");
                sw.WriteLine("vAxis: {title: 'Anos'},");
                sw.WriteLine("hAxis: {title: 'Valores'}");
                sw.WriteLine("};");

                // Instantiate and draw our chart, passing in some options.
                sw.WriteLine("var chart = new google.visualization.PieChart(document.getElementById('chart_div'));");
                sw.WriteLine("chart.draw(data, options);");

                sw.WriteLine("var chart2 = new google.visualization.ComboChart(document.getElementById('chart_div2'));");
                sw.WriteLine("chart2.draw(data2, options2);");

                sw.WriteLine("var chart3 = new google.visualization.LineChart(document.getElementById('chart_div3'));");
                sw.WriteLine("chart3.draw(data3, options3);");

                sw.WriteLine("var chart4 = new google.visualization.BarChart(document.getElementById('chart_div4'));");
                sw.WriteLine("chart4.draw(data3, options4);");

                sw.WriteLine("}");
                sw.WriteLine("</script>");
                sw.WriteLine("</head>");

                sw.WriteLine("<body>");

                sw.WriteLine(" <div id='wrapper'>");

                sw.WriteLine("<!-- Sidebar -->");
                sw.WriteLine("<div id='sidebar-wrapper'>");

                sw.WriteLine("<ul class='sidebar-nav'>");
                sw.WriteLine("</br> </br> </br>");
                sw.WriteLine("<li class='sidebar-brand'>");
                sw.WriteLine("<a href='#'>");

                sw.WriteLine("Home Gráficos");
                sw.WriteLine("</a href='home.html'>");
                sw.WriteLine("</li>");
                sw.WriteLine("<li>");
                sw.WriteLine("<p><a href='graf1.html' role='button'>IPC</a></p>");
                sw.WriteLine("</li>");
                sw.WriteLine(" <li>");
                sw.WriteLine("<p><a href='graf6.html' role='button'>Rendimento Nacional PC Anual</a></p>");
                sw.WriteLine("</li>");
                sw.WriteLine(" <li>");
                sw.WriteLine("<p><a href='graf3.html' role='button'>Remuneração Mínima</a></p>");
                sw.WriteLine("</li>");
                sw.WriteLine("<li>");
                sw.WriteLine("<p><a href='graf4.html' role='button'>Remuneração Máxima</a></p>");
                sw.WriteLine(" </li>");
                sw.WriteLine("<li>");
                sw.WriteLine("<p><a href='graf5.html' role='button'>PIB Per Capta anual</a></p>");
                sw.WriteLine("</li>");
                sw.WriteLine("<li>");
                sw.WriteLine("<p><a href='graf2.html' role='button'>Variação Anual Taxa de Inflação</a></p>");
                sw.WriteLine("</li>");
                sw.WriteLine("<li>");
                sw.WriteLine("<p><a href='graf7.html' role='button'>Rendimento Disponível PC Anual</a></p>");
                sw.WriteLine("</li>");
                sw.WriteLine("<li>");
                sw.WriteLine("<p><a href='graf8.html' role='button'>Remuneração Per Capta Anual</a></p>");
                sw.WriteLine("</li>");
                sw.WriteLine("</ul>");
                sw.WriteLine("</div>");
                sw.WriteLine("<!-- /#sidebar-wrapper -->");

                sw.WriteLine("<!-- Page Content -->");
                sw.WriteLine("<div id='page-content-wrapper'>");
                sw.WriteLine("<div class='container-fluid'>");
                sw.WriteLine("<div class='row'>");

                sw.WriteLine("</div>");
                sw.WriteLine("</div>");
                sw.WriteLine("</div>");
                sw.WriteLine("<!-- /#page-content-wrapper -->");
                sw.WriteLine("<nav class='navbar navbar-inverse navbar-fixed-top'>");
                sw.WriteLine("<div class='container'>");
                sw.WriteLine("<div class='navbar-header'>");
                sw.WriteLine(
                    "<button type='button' class='navbar-toggle collapsed' data-toggle='collapse' data-target='#navbar' aria-expanded='false' aria-controls='navbar'>");
                sw.WriteLine("<span class='sr-only'>Toggle navigation</span>");
                sw.WriteLine("<span class='icon-bar'></span>");
                sw.WriteLine("<span class='icon-bar'></span>");
                sw.WriteLine("<span class='icon-bar'></span>");
                sw.WriteLine("</button>");
                sw.WriteLine(
                    "<a class='navbar-brand' href='https://code.google.com/p/lp1415-11951/'>Trabalho de Linguagem de Programação 2014/2015</a>");
                sw.WriteLine("<div>");
                sw.WriteLine("<div id='navbar' class='navbar-collapse collapse'>");

                sw.WriteLine("<div><!--/.navbar-collapse -->");
                sw.WriteLine("<div>");
                sw.WriteLine("</nav>");

                sw.WriteLine("<!-- Main jumbotron for a primary marketing message or call to action -->");
                sw.WriteLine("<div class='jumbotron'>");
                sw.WriteLine("<div class='container'>");
                sw.WriteLine("<h1>" + titulo + "</h1>");

                sw.WriteLine("</div>");
                sw.WriteLine("</div>");

                sw.WriteLine("<!--Divs that will hold the charts-->");
                sw.WriteLine("<div class='container'>");
                sw.WriteLine("<div class='col-lg-12'>");
                sw.WriteLine("<a href='home.html' class='btn btn-default' id='menu-toggle'>Home</a>");
                sw.WriteLine("</div>");
                sw.WriteLine("<!-- Example row of columns -->");

                sw.WriteLine("<div class='container'>");
                sw.WriteLine("<!-- Example row of columns -->");

                sw.WriteLine("<div class='row'>");

                sw.WriteLine("<div class='col-md-6'>");
                sw.WriteLine("<h2>Estatísticas</h2>");
                sw.WriteLine("<div id='chart_div'>CAMPO1</div>");
                sw.WriteLine("</div>");

                sw.WriteLine("<div class='col-md-6'>");
                sw.WriteLine("<h2> </h2>");
                sw.WriteLine("<div id='chart_div2'>CAMPO2</div>");
                sw.WriteLine("</div>");

                sw.WriteLine("</div> <!-- /row -->");
                sw.WriteLine("</div> <!-- /container -->");

                sw.WriteLine("<div class='container'>");
                sw.WriteLine("<div class='row'>");

                sw.WriteLine("<div class='col-md-5'>");
                sw.WriteLine("<h2></h2>");
                sw.WriteLine("<div id='chart_div3'>CAMPO3</div>");
                sw.WriteLine("</div>");

                sw.WriteLine("<div class='col-md-2'>");
                sw.WriteLine("</div>");

                sw.WriteLine("<div class='col-md-5'>");
                sw.WriteLine("<h2> </h2>");
                sw.WriteLine("<div id='chart_div4'></div>");
                sw.WriteLine("</div>");

                sw.WriteLine("</div> <!-- /row -->");

                sw.WriteLine("<footer>");
                sw.WriteLine("<p>&copy; Adriano Leal 11951</p>");
                sw.WriteLine("</footer>");
                sw.WriteLine("</div> <!-- /container -->");
                sw.WriteLine("</div>");
                sw.WriteLine("<!-- /#wrapper -->");
                sw.WriteLine("</body>");
                sw.WriteLine("</html>");
                sw.Close();

                if (flag == 1)
                {
                    //Abre o html no browser definido.
                    System.Diagnostics.Process.Start(@"Graficos\graf" + count + ".html");
                }
            }
        }

        public double MediaVal
        {
            get { return mediaVal; }
            set { mediaVal = value; }
        }

        public List<double> Desvio
        {
            get { return desvio; }
            set { desvio = value; }
        }

        public List<double> ListaValor
        {
            get { return listaValor; }
            set { listaValor = value; }
        }

        public double SomaQuadradoDesvio
        {
            get { return somaQuadradoDesvio; }
            set { somaQuadradoDesvio = value; }
        }

        public double Variancia
        {
            get { return variancia; }
            set { variancia = value; }
        }

        public double DesvioPadrao
        {
            get { return desvioPadrao; }
            set { desvioPadrao = value; }
        }

        public double Total
        {
            get { return total; }
            set { total = value; }
        }

        public List<Dictionary<string, double>> ListaTotal
        {
            get { return listaTotal; }
            set { listaTotal = value; }
        }

        public Dictionary<string, double> Lista
        {
            get { return lista; }
            set { lista = value; }
        }

        public List<string> Teste
        {
            get { return teste; }
            set { teste = value; }
        }

        public string Titulo
        {
            get { return titulo; }
            set { titulo = value; }
        }
    }
}
